package com.example.heimaplayer.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.debug
import org.jetbrains.anko.runOnUiThread
import org.jetbrains.anko.support.v4.toast
import org.jetbrains.anko.toast

abstract class BaseFragment:Fragment(),AnkoLogger {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
        debug { "哈哈" }

    }
//    在写HomeFragment绑定数据代码之前，先来修改一下BaseFragment，有几个protected方法木有声明open，在子类中无法重写：
    protected fun init() {

    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return initView()
    }
//    获取布局view
    protected abstract fun initView(): View?

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initListener()
        initData()
//        toast("哈哈")
    }
//    数据初始化
    open protected fun initData() {

    }

    open protected fun initListener() {

    }

    open protected fun myToast(msg:String){
        context?.runOnUiThread { toast(msg) }
    }

}